package indi.h.mlx.sql;

import indi.h.mlx.sql.inter.SQLParam;

public class WhereSqlParam implements SQLParam {
	// 参数名
	private String[] name;
	// 参数值
	private Object[] value;
	// 表名
	private String[] tableName;
	// 数据匹配符,即<,>,=等
	private String[] match;
	// 数据外关联
	private String outRelation;
	// 数据内关联
	private String inRelation;

	public WhereSqlParam(String name, Object value, String tableName, String match, String relation) {
		this(new String[] { name }, new Object[] { value }, new String[] { tableName }, new String[] { match },
				relation, relation);
	}

	public WhereSqlParam(String[] name, Object[] value, String[] tableName, String[] match, String outRelation,
			String inRelation) {
		this.name = name;
		this.value = value;
		this.tableName = tableName;
		this.match = match;
		this.outRelation = outRelation;
		this.inRelation = inRelation;
	}

	public String[] getName() {
		return name;
	}

	public void setValue(Object[] value) {
		this.value = value;
	}

	public String[] getTableName() {
		return tableName;
	}

	public void setTableName(String[] tableName) {
		this.tableName = tableName;
	}

	public void setName(String[] name) {
		this.name = name;
	}

	public String[] getMatch() {
		return match;
	}

	public void setMatch(String[] match) {
		this.match = match;
	}

	public void setValue(String[] value) {
		this.value = value;
	}

	public String getOutRelation() {
		return outRelation;
	}

	public void setOutRelation(String outRelation) {
		this.outRelation = outRelation;
	}

	public String getInRelation() {
		return inRelation;
	}

	public void setInRelation(String inRelation) {
		this.inRelation = inRelation;
	}

	@Override
	public String getParam() {
		// TODO Auto-generated method stub
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < this.name.length; i++) {
			sb.append("`");
			sb.append(this.tableName[i]);
			sb.append("`.");
			sb.append("`");
			sb.append(this.name[i]);
			sb.append("` ");
			sb.append(this.match[i]);
			sb.append(" ?");
		}
		return sb.toString();
	}

	@Override
	public Object[] getValues() {
		// TODO Auto-generated method stub
		return this.value;
	}

	public Object[] getValue() {
		return value;
	}

	@Override
	public String getRelation() {
		// TODO Auto-generated method stub
		return this.outRelation;
	}

}
